class Solution
{
public:
    int countDays(int days, vector<vector<int>> &meetings)
    {
        sort(meetings.begin(), meetings.end(), [](auto &v1, auto &v2)
             {
            if(v1[0] == v2[0]){
                return v1[1] < v2[1];
            }
            return v1[0] < v2[0]; });
        int end = 0;
        int result = 0;
        int n = meetings.size();

        for (int i = 0; i < n; ++i)
        {
            result += max(meetings[i][0] - end - 1, 0);
            end = max(end, meetings[i][1]);
        }
        result += max(days - end, 0);
        return result;
    }
};